package com.geekbg.zookeeper.leader;

import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.ZooDefs.Ids;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.ACL;

import java.io.IOException;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;

import static com.geekbg.zookeeper.leader.Constants.SESSION_TIMEOUT;
import static com.geekbg.zookeeper.leader.Constants.ZOOKEEPER_STRING;

/**
 *
 *
 *
 * @author pizhihui
 * @date 2024-06-04 22:41
 */
public class Master2Runner {





    public static void main(String[] args) throws IOException {

        try {
            ZooKeeper zooKeeper = new ZooKeeper(ZOOKEEPER_STRING, SESSION_TIMEOUT, new Watcher() {
                @Override
                public void process(WatchedEvent watchedEvent) {
                    System.out.println("wachedEvent: " + watchedEvent);
                }
            });

            ArrayList<ACL> acls = Ids.OPEN_ACL_UNSAFE;

            zooKeeper.create("/tmp", "data".getBytes(), acls, CreateMode.EPHEMERAL);
        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println("创建 zk 节点成功");

        try {
            TimeUnit.SECONDS.sleep(30);
        } catch (Exception e) {

        }

        System.out.println("删除");

    }


}
